<?php

namespace App\Admin\Controllers;

use App\Models\VipWelfare;
use App\Models\vipCategory;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Encore\Admin\Controllers\AdminController;

class VipWelfaresController extends AdminController
{
    protected $title = 'VIP福利';
    
    protected function grid()
    {
        $grid = new Grid(new VipWelfare());
	
	    $grid->disableExport();
	    
	    $grid->column('name', '福利名称');
	  	$grid->column('vip_category_id', 'vip分类')->display(function () {
	        return isset($this->vipCategory) ? "{$this->vipCategory->id}: {$this->vipCategory->name}" : '';
        });
	    $grid->column('order', '排序');
	    $grid->column('created_at', '创建时间')->display(function () {
	    	return $this->created_at->toDatetimeString();
	    });
        return $grid;
    }
    
    protected function detail($id)
    {
        $show = new Show(VipWelfare::findOrFail($id));



        return $show;
    }
    
    protected function form()
    {
        $form = new Form(new VipWelfare());
	    $form->text('name', 'VIP福利名称');
	    $form->select('vip_category_id','VIP分类')->options(vipCategory::all()->pluck('name', 'id'));
	    $form->radio('is_radio', '是否是单选')->default(true)->options(config('site.bool'));
	    $form->number('order', '排序')->min(1)->default(1);

        return $form;
    }

}
